Page({

  data: {
    active: 0,
    orderList: []
  },

  onLoad(options) {
    this.getData()
  },

  // 获取数据
  getData() {
    const self = this;
    const url = 'https://erp.yilestar.com/weapp/Orders/getOrderList';
    const data = {
      tokenId: '5d9df059c27602f5a80e2176d671f9cf',
    }
    wx.request({
      url,
      data,
      method: "post",
      success: (res) => {
        console.log(res)
        const datas = res.data.data.data;
        self.setData({
          orderList: datas
        })
      }
    })
  },
  handleAgain(e) {
    const self = this;
    const data = e.currentTarget.dataset.item;
    console.log(data)
    this.addCart(data)
    // 添加到购物清单

  },

  // 添加到购物清单
  addCart(e) {
    console.log(e)
    const url = 'https://erp.yilestar.com/weapp/Carts/addCart';
    const self = this;
    e.list.map(item => {
      console.log(item)
      const data = {
        tokenId: '5d9df059c27602f5a80e2176d671f9cf', // wx.getStorageSync("tokenId")
        custId: wx.getStorageSync("custId"), // 客户唯一id ; 
        goodsId: item.goodsId,
        unitName: item.unitName, 
        saleTypeId: item.saleTypeId, 
        shopPrice: item.goodsPrice,
        unitFlg: item.unitFlg, 
        buyNum: item.goodsNum 
      }
      wx.request({
        url,
        data,
        method: "post",
        success: (res) => {

        }
      })
    })
    // setTimeout(() => {
    //   wx.redirectTo({
    //     url: '/pages/goods/card/index',
    //   })
    // }, 1000)
  },
})